#ifndef GlobalsH
#define GlobalsH

  #define _free( x ) if ( x ) { free( x ); x = NULL; }
  #define WGET(x, y) *(WORD *)&x[y]
  #define LGET(x, y) *(LONG *)&x[y]  

  #define LRAM( x ) *(LONG *)&ram[ x ]
  #define WRAM( x ) *(WORD *)&ram[ x ]

  #define TBOXHEIGHT 0x0900
  #define TBOXWIDTH  0x0130  


  #include <vcl.h>
  #include <stdio.h>
  #include <conio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <dir.h>
  #include <ctype.h>  


  typedef struct _REGZ
  { //
    WORD x;
    WORD y;
    WORD a;
    BYTE stack;
  } TREG;

  typedef struct _TFRM
  { //
    LONG lpFontOffset;  
    WORD cpl;
    BYTE height;
    BYTE width;
    BYTE bpp;
    BYTE inc;
    BYTE set[4];
  } TMAP;

  typedef struct TEXTBUF
  { //
    long posi;
    long ptr_posi;
    long ptr_index;
    long tpos;
    LONG rom_posi;
    WORD pntr;
    WORD data;
    WORD ypos;
    WORD xpos;
    WORD Max_ptrs;
    BYTE tile[256];
//    WORD *TextBuf;
    BYTE *TextBuf;
    BYTE tColor;
    BYTE index;
    BYTE ColorCount;
  } TBUF;

  typedef struct TMENUMAP
  {
     BYTE menu[128][128];
     WORD Ydim,
          Xdim,
          Ypos,
          Xpos;
  } TMEN;

  typedef struct _CODE
  { //
    WORD length;
    BYTE color;
    BYTE type;
    BYTE *text;
  } CODE;

  typedef struct TTEXTBOX
  {
     WORD *pic;//[0x300*304];
     WORD Ypos,
          Xpos,
          width,
          height;
  } TBOX;

  extern LONG lpTxtBlocks[0x100];
  extern LONG lpTxtPoints[0x100];
  extern WORD lpPointSize[0x100];

  extern Graphics::TBitmap *Vga;
  extern char dirc[512];
  extern char txtf[512];
  extern char romf[512];
  extern char cur_dir[MAXPATH];
  //
  extern long FoundAt;
  extern WORD *ScrBuf;
  extern BYTE *ram;
  extern BYTE *rom;
  extern BYTE *tiles;
  extern TMAP map;
  extern TBUF txt;
  extern TREG reg;
  extern TMEN men;
  extern TBOX textbox[2];  
  extern LONG cur_str;

  extern int  StartPos;
  extern int  ToEnd;
  extern int  curLine;
  extern int  indexLine;
  extern int  WinX;
  extern int  WinY;
  extern BYTE EStr[0x1000];
  extern CODE codes[0x00100];
  extern CODE duals[0x10000];
//  extern WORD EStr[0x1000];
  extern BYTE *_MATH;
  extern bool iCanDraw;
  extern bool isActive;  

  extern LONG GetIndex( char *strg );
  extern void Dec2Bin( BYTE *string, LONG valu, BYTE size );
  extern long Snes2Pc( long ofs );
  extern long Pc2Snes( long ofs );
  extern long FileSize( FILE *tf );
  extern void MenuMap( WORD *Dest, TMEN *map, int Width, bool type );
  extern void memcpyw( WORD *Dest, WORD *Srce, long lcSize, char type );
  extern void memsetw( WORD *Dest, WORD Data, long lcSize );
  extern void puttile( WORD *Dest, WORD *Srce, char y, char x, int Width, bool mask );
  extern void Shift( BYTE *pic, int  h, int  w );  

  #include "A2_Main.h"
  #include "dos5x5.h"
  #include "Menu.h"  
  #include "TextEdit.h"
  #include "KanaString.h"  
  #include "HexData.h"
  #include "DecompBlock.h"
  #include "ListBlock.h"      

#endif
